package netWorkPrograming.tcp.tcp06;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/28
 */
public class ServerDemo {
    public static void main(String[] args) {
        System.out.println("--------------服务端------------------");
        ThreadPool pool=new ThreadPool(2,2);
        ServerSocket ss=null;
        try {
            ss=new ServerSocket(8888);
            System.out.println("服务端持续监听端口号：8888");
            while (true) {
                Socket s=ss.accept();
                System.out.println("客户端:"+s.getRemoteSocketAddress()+"已连接！");
                pool.execute(new ReaderThread(s));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if(ss!=null){
                try {
                    ss.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
